package com.lzq.leetcode.lanqiao;

import java.util.Arrays;
import java.util.Scanner;

public class s2128 {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int n = scan.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = scan.nextInt();
        }
        int m = scan.nextInt();

        int[] cnt = new int[n];
        for (int i=0; i<m; i++) {
            int l = scan.nextInt();
            int r = scan.nextInt();
            cnt[l-1] += 1;
            if (r < n)  cnt[r] -= 1;
        }

        for (int i=1; i<n; i++) {
            cnt[i] = cnt[i] +cnt[i-1];
        }

        // 统计初始综合
        long sum = 0;
        for (int i=0; i<n; i++) {
            sum += (long)nums[i] * cnt[i];
        }

        Arrays.sort(nums);
        Arrays.sort(cnt);
        for (int i=0; i<n; i++) {
            sum -= (long)nums[i] * cnt[i];
        }
        System.out.println(-sum);
        scan.close();
    }
}
